package com.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.project.bean.DeptBean;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Title: IDeptMapper
 * @Package: com.project.mapper
 * @Description:
 * @Author: Liang-Xie
 * @Date: 2022/7/15 - 11:54
 */
@SuppressWarnings("all")
@Mapper
public interface IDeptMapper extends BaseMapper<DeptBean> {
    @Select("SELECT  d.*, COUNT(e.`pk_emId`)emNum  FROM t_dept d LEFT JOIN t_employee e ON e.`fk_deptId`=d.`pk_deptId` GROUP BY d.`pk_deptId`;\n")
    @ResultMap("deptMap")
    public List<DeptBean>findAll();
    @Delete("delete from t_employee where fk_deptId=#{id};"+
        "delete from t_dept where pk_deptId=#{id};")
    public void delCasede(Integer id);

    @Delete("update t_employee set fk_deptId=null where fk_deptId=#{id};"
            +"delete from t_dept where pk_deptId=#{id}")
    public void delSetNull(Integer id);
}
